package mail.gui;

import java.util.ArrayList;
import java.util.Date;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import javax.swing.table.AbstractTableModel;

import mail.MailSession;
import mail.bean.AccountBean;
import mail.bean.EmailBean;

public class ListTableModel extends AbstractTableModel {
	private int columnCount = 4;
	private static String[] columnNames = {"Sender", "Subject", "Send Date", "Size"};
	private ArrayList<EmailBean> emailList = null;
	
	public ListTableModel() {
//		AccountBean account = new AccountBean("zjyzju");
//		account.setHost("www.163.com");
//		account.setUser("zjyzju@163.com");
//		account.setRecHost("pop.163.com");
//		account.setRecProtocol("pop3");
//		account.setSendHost("smtp.163.com");
//		account.setSendProtocol("smtp");
//		account.setNeedAuth(true);
//		MailSession mail = new MailSession(account);
//		emailList = mail.receiveMailList(account);
	}
	
	public String getColumnName(int column) {
		return columnNames[column];
	}

	public int getColumnCount() {
		return columnCount;
	}

	public int getRowCount() {
	  if(emailList == null) {
	    return 0;
	  }
		return emailList.size();
	}

	public Object getValueAt(int rowIndex, int columnIndex) {
		if(emailList == null || rowIndex >= emailList.size()) {
			return null;
		}
		EmailBean msg = emailList.get(rowIndex);
    Object obj = null;
    switch (columnIndex) {
    case 0:
      obj = msg.getSender();
      break;
    case 1:
      obj = msg.getSubject();
      break;
    case 2:
      obj = msg.getSendDate();
      break;
    case 3:
      obj = msg.getSize();
      break;
    default:
      break;
      	
      }
      return obj;
	}

  public ArrayList<EmailBean> getEmailList() {
    return emailList;
  }

  public void setEmailList(ArrayList<EmailBean> emailList) {
    this.emailList = emailList;
  }

}
